import config from "./config"
import api from './api'
import tool from './utils/tool'
import http from "./utils/request"
import { permission, rolePermission } from './utils/permission'

import bydTable from './components/bydTable'
import bydFilterBar from './components/bydFilterBar'
import bydUpload from './components/bydUpload'
import bydUploadMultiple from './components/bydUpload/multiple'
import bydFormTable from './components/bydFormTable'
import bydTableSelect from './components/bydTableSelect'
import bydPageHeader from './components/bydPageHeader'
import bydSelect from './components/bydSelect'
import bydDialog from './components/bydDialog'
import bydForm from './components/bydForm'
import bydTitle from './components/bydTitle'
import bydWaterMark from './components/bydWaterMark'
import bydQrCode from './components/bydQrCode'

import bydStatusIndicator from './components/bydMini/bydStatusIndicator'
import bydTrend from './components/bydMini/bydTrend'

import auth from './directives/auth'
import role from './directives/role'
import time from './directives/time'
import copy from './directives/copy'
import errorHandler from './utils/errorHandler'

import * as elIcons from '@element-plus/icons-vue'
import * as bydIcons from './assets/icons'

export default {
	install(app) {
		//挂载全局对象
		app.config.globalProperties.$conf = config;
		app.config.globalProperties.$tool = tool;
		app.config.globalProperties.$http = http;
		app.config.globalProperties.$api = api;
		app.config.globalProperties.$auth = permission;
		app.config.globalProperties.$role = rolePermission;

		//注册全局组件
		app.component('bydTable', bydTable);
		app.component('bydFilterBar', bydFilterBar);
		app.component('bydUpload', bydUpload);
		app.component('bydUploadMultiple', bydUploadMultiple);
		app.component('bydFormTable', bydFormTable);
		app.component('bydTableSelect', bydTableSelect);
		app.component('bydPageHeader', bydPageHeader);
		app.component('bydSelect', bydSelect);
		app.component('bydDialog', bydDialog);
		app.component('bydForm', bydForm);
		app.component('bydTitle', bydTitle);
		app.component('bydWaterMark', bydWaterMark);
		app.component('bydQrCode', bydQrCode);
		app.component('bydStatusIndicator', bydStatusIndicator);
		app.component('bydTrend', bydTrend);

		//注册全局指令
		app.directive('auth', auth)
		app.directive('role', role)
		app.directive('time', time)
		app.directive('copy', copy)

		//统一注册el-icon图标
		for(let icon in elIcons){
			app.component(`ElIcon${icon}`, elIcons[icon])
		}
		//统一注册byd-icon图标
		for(let icon in bydIcons){
			app.component(`BydIcon${icon}`, bydIcons[icon])
		}

		//全局代码错误捕捉
		app.config.errorHandler = errorHandler
	}
}
